'''money = 500
list_shopping_cart = []
list_goods = {"糖果": 12, "啤酒": 55, "牛奶": 60, "裤子": 120, "短袖": 30, "巧克力": 50, "瓜子": 12}
is_continue = True
while money > 0:
    print(list_goods)
    print("请输入要选购的商品名")
    good = input()
    if good in list_goods:
        if money > list_goods.get(good):
            print("加入购物车成功")

            list_shopping_cart.append(good+str(list_goods.get(good))+"元")
            money -= list_goods.get(good)
        else:
            print("穷鬼，钱不够！请到其他超市购买！")
    else:
        print("没有这个商品，别瞎弄！")
    print("是否继续购买: q.结束并打印，其他键继续")
    if input() == 'q' or input() == 'Q':
        print(list_shopping_cart)
        break
    else:
        continue'''
import datetime
import random


class Account:
    name = ''
    money = 0
    coupon_list = []

    def __init__(self, name, money):
        self.name = name
        self.money = money


class Coupon:
    name: ''
    discount: 0.0

    def __init__(self, name, discount):
        self.name = name
        self.discount = discount

    def __str__(self):
        return f"Coupon(名称= {self.name},折扣 = {self.discount})"


class Goods:
    name: ''
    price: 0

    def __init__(self, name, price):
        self.name = name
        self.price = price

    def __str__(self):
        return f"Goods(name={self.name},price={self.price})"


class ShoppingCart:
    name = ''
    number = 0
    unit_price = 0


user = Account("张三", 5000)

good_list = [Goods("空调", 2000), Goods("冰箱", 3000), Goods("电视", 2500), Goods("电动车", 2000), Goods("手机", 2000),
             Goods("电脑", 6000), Goods("衣服", 200), Goods("鞋子", 290)
    , Goods("平板", 2000), Goods("鼠标", 120), Goods("键盘", 200), Goods("显卡", 4000), Goods("水杯", 20), Goods("电竞椅", 200),
             Goods("外套", 120), Goods("牛肉干", 80)]
coupon_list = [Coupon("空调", 0.8), Coupon("冰箱", 0.7), Coupon("空调", 0.7), Coupon("手机", 0.7), Coupon("电脑", 0.7),
               Coupon("衣服", 0.7), Coupon("鞋子", 0.7)
    , Coupon("平板", 0.7), Coupon("鼠标", 0.7), Coupon("显卡", 0.7)]
shopping_cart_list = []
for i in range(0, len(good_list)):
    print(good_list[i].name + "--" + str(good_list[i].price) + "元", end=" ")
    if i % 5 == 0:
        print()
n = random.choice(range(0, 10))
print("恭喜你抽奖抽到", coupon_list[n])
user.coupon_list.append(coupon_list[n])
while user.money >= 0:
    print("请输入要购买的商品名称")
    found_goods = None
    good_name = input()
    #退出系统
    if good_name == 'q' or good_name == 'Q':
        print("退出系统")
        break
    if good_name == 't':
        print("请输入要退货的商品名称")
        t_name = input()
        shop_c = None
        for scl in shopping_cart_list:
            if t_name == scl.name:
                user.money += scl.unit_price * scl.number
                shopping_cart_list.remove(scl)
                print("购物车移除成功")
                break
        continue
    if good_name == 'i':
        print("购物人："+user.name)
        print("购物日期："+str(datetime.datetime.now()))
        print("卡余额:"+ str(user.money))
        total = 0
        for scl in shopping_cart_list:
            print(scl.name+"--"+str(scl.unit_price)+"元"+"--"+"*"+str(scl.number))
            total1 = scl.unit_price*scl.number
            total += total1
        print("总价为："+str(total)+"元")
        break
    for g in good_list:
        if g.name == good_name:
            found_goods = g
            break
    if found_goods:
        if user.money > found_goods.price or user.money > found_goods.price * user.coupon_list[0].discount:
            print("加入购物车成功")
            datetime1 = datetime.datetime.now()

            if not shopping_cart_list:
                sc = ShoppingCart()
                sc.name = found_goods.name
                if found_goods.name == user.coupon_list[0].name:
                    sc.unit_price = found_goods.price * user.coupon_list[0].discount
                    user.money -= found_goods.price * user.coupon_list[0].discount
                else:
                    sc.unit_price = found_goods.price
                    user.money -= found_goods.price
                sc.number = 1
                shopping_cart_list.append(sc)
            else:
                is_flag = True
                for spl in shopping_cart_list:
                    if spl.name == found_goods.name:
                        is_flag = False
                        spl.number += 1
                        if found_goods.name == user.coupon_list[0].name:
                            sc = ShoppingCart()
                            sc.unit_price = found_goods.price * user.coupon_list[0].discount
                            user.money -= found_goods.price * user.coupon_list[0].discount
                        else:
                            sc.unit_price = found_goods.price
                            user.money -= found_goods.price
                if is_flag:
                    sc = ShoppingCart()
                    sc.number += 1
                    sc.name = found_goods.name
                    if found_goods.name == user.coupon_list[0].name:
                        sc.unit_price = found_goods.price * user.coupon_list[0].discount
                        user.money -= found_goods.price * user.coupon_list[0].discount
                    else:
                        sc.unit_price = found_goods.price
                        user.money -= found_goods.price
                    shopping_cart_list.append(sc)


            print("-------是否继续购买-----\n--------i结算-------\n--------q/Q退出--------\n---------t退货--------")
        else:
            print("穷鬼！钱不够，请到其他超市购买")

    else:
        print("没有这个商品，别瞎弄")


